<%@page import="org.proddevplm.dao.data.swot.SwotAnalysis"%>
<%@page import="org.proddevplm.constants.ControllerConstants"%>
<%@page import="org.proddevplm.business.activity.constants.ActivityConstants" %>

<script>
	
	$(function(){
		$("button").button();
	});
	
	function validateSwot(name){
		var arguments = "swotName="+name;
		ajaxCall("toolsManager", "17", arguments, printStatus);
	}
	
	function printStatus(data){
		alert(data);
	}
	
	function checkCompletion(name){
		$("#activityName").val(name);
		var arguments = "activityName="+name;
		ajaxCall("dataAccessManager","24",arguments, approve);
	}
	
	function approve(data){
		var check = parseInt(data);
		if(check==0){
			document.forms['approveForm'].submit();
		}
		else{
			alert('Not all SWOT analyses were reviewed');
		}
	}
	
</script>

<%
	SwotAnalysis selectedSwot = (SwotAnalysis)session.getAttribute("selectedSwot");
%>

<div style="width:auto">

	<div style="margin:10 0 0; float:left;">
		<div style="width:200px; text-align:left; float:left">
			<b>Analysis' name:</b>
		</div>
		<div style="width:200px; float:left; text-align:left">
			<%=selectedSwot.getName() %>
		</div>
		<div style="float:left; text-align:left; margin-left:50px">
			<b>Analysis' author:&nbsp</b>
		</div>
		<div style="width:200px; float:left; text-align:left">
			<%=selectedSwot.getAuthor() %>
		</div>
		<div style="float:left; text-align:left; margin-left:50px">
			<b>Analysis' status:</b>
		</div>
		<div style="width:200px; float:left; text-align:left">
			<%if(selectedSwot.isStatus()){ %>
				&nbsp approved
			<%}else{ %>
				&nbsp not approved
			<%} %>
		</div>
	</div>
	<div style="clear:both"></div>
	
	<div style="margin:5 0 0; float:left">
		<div style="width: 200px; text-align:left; float: left;">
			<b>Competitor:</b>
		</div>
		<div style="width:200px; float:left; text-align:left;">
			<%=selectedSwot.getCompetitor()%>
		</div>
		<!--  <input type="text" disabled="disabled" value="<%=selectedSwot.getCompetitor()%>" style="width:200px; font-weight:bold; float:left;"/>-->
	</div>
	<div style="clear:both"></div>
	
	<div style="margin:5 0 0; float:left">
		<div style="width: 200px; text-align:left; float: left;">
			<b>Competitor's product:</b>
		</div>
		<div style="width:200px; float:left; text-align:left;">
			<%=selectedSwot.getCompProduct()%>
		</div>
		<!-- <input type="text" disabled="disabled" value="<%=selectedSwot.getCompProduct()%>" style="width:200px; float:left;"/> -->
	</div>	
	<div style="clear:both"></div>
	
	<table style="float:left; margin:5 0 0; width:100%; border: 1px solid #B8B8B8; -moz-border-radius:5px; font-size:small" cellpadding="0" cellspacing="0" border="1">		
		<tr >
			<td colspan="2" style="text-align:center; font-weight:bold; background-color:#EEE0E5">SWOT Table</td>
		</tr>
		<tr>
			<td style="width:50%; font-weight: bold; text-align:center; background-color:#E6E6FA">Strengths</td>
			<td style="width:50%; font-weight: bold; text-align:center; background-color:#E6E6FA">Weaknesses</td>
		</tr>
		<tr>
			<td>
				<select size="5" style="border:none; width:100%">
					<%String strengths = selectedSwot.getStrengths();
					String[] sArray = strengths.split("~");
					for(int i=0; i<sArray.length; i++){%>
						<option><%=sArray[i] %></option>
					<%} %>
				
				</select>	
			</td>
			<td>
				<select size="5" style="border:none; width:100%">
					<%String weaks = selectedSwot.getWeaknesses();
					String[] wArray = weaks.split("~");
					for(int i=0; i<wArray.length; i++){%>
						<option><%=wArray[i] %></option>
					<%} %>
				</select>
			</td>
		</tr>
		<tr>
			<td style="width:50%; font-weight: bold; text-align:center; background-color:#E6E6FA">Opportunities</td>
			<td style="width:50%; font-weight: bold; text-align:center; background-color:#E6E6FA">Threats</td>
		</tr>
		<tr>
			<td>
				<select size="5" style="border:none; width:100%">
					<%String opps = selectedSwot.getOpportunities();
					String[] oArray = opps.split("~");
					for(int i=0; i<oArray.length; i++){%>
						<option><%=oArray[i] %></option>
					<%} %>
				</select>	
			</td>
			<td>
				<select size="5" style="border:none; width:100%">
					<%String threats = selectedSwot.getThreats();
					String[] tArray = threats.split("~");
					for(int i=0; i<tArray.length; i++){%>
						<option><%=tArray[i] %></option>
					<%} %>
				</select>
			</td>
		</tr>			
	</table>	
	<div style="clear:both"></div>
	
	<div style="margin:5 0 0; float:left; width:100%">
		<button id="validateSwot" name="validateSwot" onclick="validateSwot('<%=selectedSwot.getName()%>')" style="width:20%; float:left; font-weight:bold">Validate analysis</button>
		<button id="approveActivity" name="approveActivity" onclick="checkCompletion('<%=selectedSwot.getActivityName()%>')" style="width:20%; float:right; font-weight:bold">Approve activity</button> 
	</div>
	
	<form name="approveForm" method="post" action="/proddev/controller">
		<input type = "hidden" name = "<%=ControllerConstants.MANAGER_KEY%>" value = "<%=ControllerConstants.ACTIVITY_MANAGER%>"/>
		<input type = "hidden" name = "<%=ControllerConstants.METHOD_KEY%>" value = "<%=ActivityConstants.UPDATE_ACTIVITY%>"/>
		<input type="hidden" name="activityName" id="activityName">
	</form>
	<div style="clear:both"></div>
</div>